package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import org.come.entity.Gang;
import org.come.mouslisten.ZDCYMouslisten;
import org.come.until.ScrollUI;
import org.come.until.SrcollPanelUI;
import org.come.until.Util;

import com.tool.btn.CreatBangBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



/**
 * 加入帮派面板
 * @author Administrator
 *
 */
public class JoinBangJpanel extends JPanel {

	private Vector<Vector<String>> verVectors;// 设置所有帮派成员的集合
	private Vector<String> veStrings;// 放置帮派成员信息的集合
	private List<Gang> gangs;// 存放所有帮派的信息
	// 帮派成员信息表格
	private JTable tableMsg;
	// 帮派成员信息表格中的对象
	private DefaultTableModel tableModel;
	// 放置帮派宗旨的文本域
	private JTextArea jTextArea;
	// 帮派成员信息列表滚动条
	private JScrollPane jScrollPane1;
	// 帮派宗旨滚动条
	private JScrollPane jScrollPane2;
	//	private JButton applybtn;// 申请按钮
	private CreatBangBtn btnbang;//创建帮派按钮
	private CreatBangBtn btnbang1;//创建帮派按钮

	public JoinBangJpanel() throws Exception {
		String style = MyIsif.getStyle();
		if ("水墨UI".equals(style)) {
		// 键盘监听
		this.setPreferredSize(new Dimension(458, 519));
		this.setBackground(UIUtils.Color_BACK);
		this.setLayout(null);

		tableModel = new DefaultTableModel();
		verVectors = new Vector<Vector<String>>();
		veStrings = new Vector<String>();
		veStrings.add("adscf");
		veStrings.add("adscf");
		veStrings.add("adscf");
		veStrings.add("adscf");
		veStrings.add("adscf");
		verVectors.add(veStrings);
		tableModel.setDataVector(verVectors, Util.vector3);

		// 帮派成员信息表格
		tableMsg = new JTable() {
			{
				setOpaque(false);
			} // instance initializer
			@Override
			public boolean isCellEditable(int row, int column) {
				// TODO Auto-generated method stub
				return false;
			}
		};
		tableMsg.setShowGrid(false);

		DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
		renderer.setHorizontalAlignment(SwingConstants.CENTER);
		tableMsg.setDefaultRenderer(Object.class, renderer);

		JTableHeader header = tableMsg.getTableHeader();

		// 设置表头的高度
		header.setPreferredSize(new Dimension(header.getWidth(), 0));
		tableMsg.getTableHeader().setBackground(UIUtils.Color_BACK);
		// tableMsg.getTableHeader().setForeground(Color.ORANGE);
		tableMsg.getTableHeader().setVisible(true);
		tableMsg.getTableHeader().setBorder(
				BorderFactory.createLineBorder(Color.ORANGE));

		tableMsg.setSelectionBackground(UIUtils.Color_BACK);
		tableMsg.setSelectionForeground(Color.red);
		tableMsg.setForeground(Color.yellow);
		tableMsg.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		tableMsg.setBackground(UIUtils.Color_BACK);
		tableMsg.setModel(tableModel);

		// 设置列间距
		tableMsg.getColumnModel().getColumn(0).setPreferredWidth(108);
		tableMsg.getColumnModel().getColumn(1).setPreferredWidth(60);
		tableMsg.getColumnModel().getColumn(2).setPreferredWidth(57);
		tableMsg.getColumnModel().getColumn(3).setPreferredWidth(68);
		tableMsg.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		tableMsg.isCellEditable(1, 1);
		tableMsg.setEnabled(true);

		// tableMsg.setModel(tableModel);
		tableMsg.addMouseListener(new MouseListener() {

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				int index = tableMsg.getSelectedRow();
				jTextArea.setText(gangs.get(index).getIntroduction());

			}

			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub

			}
		});

		// 帮派成员信息表格滚动条
		jScrollPane1 = new JScrollPane();
		jScrollPane1.setViewportView(tableMsg);
		jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		jScrollPane1.getVerticalScrollBar().setUI(new SrcollPanelUI());
		jScrollPane1.getViewport().setOpaque(false);
		jScrollPane1.setOpaque(false);
		jScrollPane1.setBounds(51, 72, 298+82, 145+40);
		jScrollPane1.setBackground(UIUtils.Color_BACK);
		jScrollPane1.setBorder(BorderFactory.createEmptyBorder());
		jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		this.add(jScrollPane1);

		// 帮派宗旨文本域
		jTextArea = new JTextArea() {
			{
				setOpaque(false);
			} // instance initializer
		};
		jTextArea.setSelectionColor(new Color(55, 23, 31));
		jTextArea.setForeground(Color.WHITE);
		jTextArea.setSelectedTextColor(Color.WHITE);
		jTextArea.setLineWrap(true);
		jTextArea.setFont(new Font("微软雅黑", 1, 14));
		jTextArea.setBackground(UIUtils.Color_BACK);

		// 帮派宗旨滚动条
		jScrollPane2 = new JScrollPane(jTextArea);
		jScrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		jScrollPane2.getVerticalScrollBar().setUI(new SrcollPanelUI());
		jScrollPane2.getViewport().setOpaque(false);
		jScrollPane2.setOpaque(false);
		jScrollPane2.setBounds(132, 338, 298, 128);
		jScrollPane2.setBorder(BorderFactory.createEmptyBorder());
		jScrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		this.add(jScrollPane2);
		btnbang=new CreatBangBtn("skin/8100226/newbutton/B22.png", 1,"加入帮派" ,this,null);
		btnbang.setBounds(280, 477, 99, 24);
		this.add(btnbang);
		btnbang1=new CreatBangBtn("skin/8100226/newbutton/B22.png", 1,"联系帮主" ,this,null);
		btnbang1.setBounds(90, 477, 99, 24);
		this.add(btnbang1);
		}else {
			// 键盘监听
			this.setPreferredSize(new Dimension(333, 435));
			this.setBackground(UIUtils.Color_BACK);
			this.setLayout(null);

			tableModel = new DefaultTableModel();
			verVectors = new Vector<Vector<String>>();
			veStrings = new Vector<String>();
			veStrings.add("adscf");
			veStrings.add("adscf");
			veStrings.add("adscf");
			veStrings.add("adscf");
			veStrings.add("adscf");
			verVectors.add(veStrings);
			tableModel.setDataVector(verVectors, new Vector<>(Util.vector3));

			// 帮派成员信息表格
			tableMsg = new JTable() {
				{
					setOpaque(false);
				} // instance initializer
				@Override
				public boolean isCellEditable(int row, int column) {
					// TODO Auto-generated method stub
					return false;
				}
			};
			tableMsg.setShowGrid(false);

			DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
			renderer.setHorizontalAlignment(SwingConstants.CENTER);
			tableMsg.setDefaultRenderer(Object.class, renderer);

			JTableHeader header = tableMsg.getTableHeader();

			// 设置表头的高度
			header.setPreferredSize(new Dimension(header.getWidth(), 0));
			tableMsg.getTableHeader().setBackground(UIUtils.Color_BACK);
			// tableMsg.getTableHeader().setForeground(Color.ORANGE);
			tableMsg.getTableHeader().setVisible(true);
			tableMsg.getTableHeader().setBorder(
					BorderFactory.createLineBorder(Color.ORANGE));

			tableMsg.setSelectionBackground(UIUtils.Color_BACK);
			tableMsg.setSelectionForeground(Color.red);
			tableMsg.setForeground(Color.yellow);
			tableMsg.setFont(new Font("微软雅黑", Font.PLAIN, 16));
			tableMsg.setBackground(UIUtils.Color_BACK);
			tableMsg.setModel(tableModel);

			// 设置列间距
			tableMsg.getColumnModel().getColumn(0).setPreferredWidth(88);
			tableMsg.getColumnModel().getColumn(1).setPreferredWidth(60);
			tableMsg.getColumnModel().getColumn(2).setPreferredWidth(57);
			tableMsg.getColumnModel().getColumn(3).setPreferredWidth(48);
			tableMsg.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			tableMsg.isCellEditable(1, 1);
			tableMsg.setEnabled(true);

			// tableMsg.setModel(tableModel);
			tableMsg.addMouseListener(new MouseListener() {

				@Override
				public void mouseReleased(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mousePressed(MouseEvent e) {
					// TODO Auto-generated method stub
					int index = tableMsg.getSelectedRow();
					jTextArea.setText(gangs.get(index).getIntroduction());

				}

				@Override
				public void mouseExited(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mouseEntered(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mouseClicked(MouseEvent e) {
					// TODO Auto-generated method stub

				}
			});

			// 帮派成员信息表格滚动条
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(tableMsg);
			jScrollPane1.setVerticalScrollBarPolicy(22);
			jScrollPane1.getVerticalScrollBar().setUI(new ScrollUI());
			jScrollPane1.getViewport().setOpaque(false);
			jScrollPane1.setOpaque(false);
			jScrollPane1.setBounds(35, 58, 265, 145);
			jScrollPane1.setBackground(UIUtils.Color_BACK);
			jScrollPane1.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane1.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane1);

			// 帮派宗旨文本域
			jTextArea = new JTextArea() {
				{
					setOpaque(false);
				} // instance initializer
			};
			jTextArea.setSelectionColor(new Color(55, 23, 31));
			jTextArea.setForeground(Color.WHITE);
			jTextArea.setSelectedTextColor(Color.WHITE);
			jTextArea.setLineWrap(true);
			jTextArea.setFont(new Font("微软雅黑", 1, 14));
			jTextArea.setBackground(UIUtils.Color_BACK);

			// 帮派宗旨滚动条
			jScrollPane2 = new JScrollPane(jTextArea);
			jScrollPane2.setVerticalScrollBarPolicy(22);
			jScrollPane2.getVerticalScrollBar().setUI(new ScrollUI());
			jScrollPane2.getViewport().setOpaque(false);
			jScrollPane2.setOpaque(false);
			jScrollPane2.setBounds(35, 230, 265, 145);
			jScrollPane2.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane2.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane2);
			btnbang=new CreatBangBtn("inkImg/hongmu/1_png.button.btn_xy.png", 1,"加入帮派" ,this,null);
			btnbang.setColors(UIUtils.COLOR_BTNPUTONG2);
			btnbang.setFont(UIUtils.TEXT_HY88);
			btnbang.setBounds(140, 390, 80, 26);
			this.add(btnbang);
		}
	}
	private ImageIcon icon;
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		String style = MyIsif.getStyle();
		if ("水墨UI".equals(style)) {
		// 调用帮派图片
		if (icon==null)icon=new ImageIcon("inkImg/newbackground/S61.png");
		g.drawImage(icon.getImage(), 0, 0, 458, 519, this);
		}else {
			// 调用帮派图片
			if (icon==null)icon=new ImageIcon("img/xy2uiimg/58_png.xy2uiimg.quergroup.png");
			g.drawImage(icon.getImage(), 0, 0, 333, 435, this);
		}
	}

	public JTable getTableMsg() {
		return tableMsg;
	}

	public void setTableMsg(JTable tableMsg) {
		this.tableMsg = tableMsg;
	}

	public JTextArea getjTextArea() {
		return jTextArea;
	}

	public void setjTextArea(JTextArea jTextArea) {
		this.jTextArea = jTextArea;
	}

	public List<Gang> getGangs() {
		return gangs;
	}

	public void setGangs(List<Gang> gangs) {
		this.gangs = gangs;
	}

	public DefaultTableModel getTableModel() {
		return tableModel;
	}

	public void setTableModel(DefaultTableModel tableModel) {
		this.tableModel = tableModel;
	}

	public Vector<Vector<String>> getVerVectors() {
		return verVectors;
	}

	public void setVerVectors(Vector<Vector<String>> verVectors) {
		this.verVectors = verVectors;
	}

	public Vector<String> getVeStrings() {
		return veStrings;
	}

	public void setVeStrings(Vector<String> veStrings) {
		this.veStrings = veStrings;
	}


}
